package com.yylending.las.lending.increase;

import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yylending.las.Global;
import com.yylending.las.common.AESEntity;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

/**
 * Created by Pengrf on 2017/11/21.
 * Copyright  2017 www.yyfax.com. All Rights Reserved.
 */
public class FinishPromoteProcessModel extends Model {
	public static final int FINISH_PROMOTE_PROCESS = 999110;

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		switch (functionalCode) {
			case FINISH_PROMOTE_PROCESS:
				return service.finishPromoteProcess(Global.LOGIN_TOKEN, (AESEntity) params);
		}
		return null;
	}

	@Override
	public void onNext(Object entity) {
		FinishPromoteResult result = cast(entity);
		switch (result.requestCode) {
			case FINISH_PROMOTE_PROCESS:
				FinishPromoteResult finishPromote = cast(entity);
				EventAgent.post(finishPromote);
				break;
		}
	}

	private interface Service {

		@POST("server/loan/finishPromoteProcess")
		Observable<FinishPromoteResult> finishPromoteProcess(@Header("token") String token, @Body AESEntity params);
	}

	public static class FinishPromoteParams {
		/**
		 * err 密码错误等错误重试
		 * fin 完成
		 */
		public String type;

		public FinishPromoteParams(String type) {
			this.type = type;
		}
	}

	public static class FinishPromoteResult extends BaseResultEntity<PromoteResult> {

	}

	public static class PromoteResult {
		/**
		 * 300 重试返回
		 * 310 不能提额 完成返回
		 */
		public String promoteAmount;

		public PromoteResult(String promoteAmount) {
			this.promoteAmount = promoteAmount;
		}
	}
}
